/*
 * This game is called HighLow and goes through a single deck of cards.
 * Cards from the deck are dealt to the user, one by one. 
 * The user is asked to predict whether the next card will be higher and lower.
 * The user's score is how many correct predictions are made.
*/

game HighLow{
	main(){	
		"This game is called HighLow and goes through a single deck of cards.";
	    "Cards from the deck are dealt to you, one by one.";
	    "You need to predict whether the next card will be higher and lower.";
	    "The game ends when you make a wrong prediction.";
	    "Your score is how many correct consecutive predictions you make.";
		
		score = play(); /* Play the game and get the score. */
		"";
		"Your score was",score,"!";
	}
	
	int play(){
		Card currentCard, nextCard;   
		int gameScore, guess;
		
		gameScore = 0;
		deck.shuffle();
		currentCard = deck.draw();
		"The first card is the",currentCard.name,"with value",currentCard.value;
		
		while(deck.hasCard()){ /* Loop ends when there are no more cards or the user is wrong. */
			"Do you think the next card be lower (0) or higher (1)?";
			guess = nextInt();
			if (guess*guess != guess)
				"Please respond with 0 or 1.";
			nextCard = deck.draw();
			"The next card is",nextCard.name,"with value",nextCard.value;
			
			if(nextCard.value = currentCard.value)
			{
				"The value is the same as the previous card.";
				"You lose on ties.  Sorry!";
				break;  /* End the game. */
			}
			else if (nextCard.value > currentCard.value) {
				if (guess == 1) {
				   "Your prediction was correct.";
				   gameScore++;
				}
				else {
				   "Your prediction was incorrect.";
				   break;  /* End the game. */
				}
			}
			else {  /* nextCard is lower */
				if (guess == 0) {
				   "Your prediction was correct.";
				   gameScore++;
				}
           		else {
           			"Your prediction was incorrect.";
           			break;  /* End the game. */
           		}
			}
			/* To set up for the next iteration of the loop, the nextCard
            becomes the currentCard, since the currentCard has to be
            the card that the user sees, and the nextCard will be
            set to the next card in the deck after the user makes
            his prediction.  */
			currentCard = nextCard;
			"";
			"The card is",currentCard.name,"with value",currentCard.value;
		}	/* end of while loop */
		"";
		"The game is over.";
		"You made",gameScore,"correct predictions.";
		"";
		return gameScore;
	}
}